﻿Imports System.Web.Script.Serialization
Imports System.Web.Script.Services
Public Class oHierarchyDetail
    Public Function GetHierarchyDetailByHierarchyID(ByVal dataBaseName As String, ByVal hierarchyID As String) As DataSet
        Dim connect As New Connection()
        Try
            Dim ds As New DataSet("HierarchyDetail")
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            If errMsg.Length = 0 Then
                Dim query As New StringBuilder
                query.Append("SELECT T0.*")
                query.Append(" FROM oHierarchyDetail T0 JOIN oHierarchy T1 ON T0.HierarchyID = T1.HierarchyID")
                query.Append("  WHERE T0.HierarchyID = @Param1")
                ds = connect.ObjectGetAll_Query_SAP(query.ToString(), New Object() {hierarchyID})
            End If
            Return ds
        Catch ex As Exception
            Throw ex
        End Try
    End Function
    Public Function CreateHierarchyDetail(ByVal dataBaseName As String, ByVal hierarchyID As String, ByVal hierarchyDetailName As String, ByVal hierarchyFatherID As String) As String
        Dim connect As New Connection()
        Try
            Dim jss As New JavaScriptSerializer()
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            Dim query As New StringBuilder
            If errMsg.Length = 0 Then
                query.Append("INSERT INTO [oHierarchyDetail] ")
                query.Append(" ([HierarchyID]")
                query.Append(",[HierarchyDetailName]")
                query.Append(",[HierarchyFatherID])")
                query.Append(" VALUES (@Param1,@Param2,@Param3)")
                Dim count As Integer = connect.Object_Execute_SAP(query.ToString(), New Object() {hierarchyID, _
                                                                                                  hierarchyDetailName, _
                                                                                                  hierarchyFatherID})
            Else
                Return errMsg
            End If
        Catch ex As Exception
            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Public Function UpdateHierarchyDetail(ByVal dataBaseName As String, ByVal hierarchyDetailID As String, ByVal hierarchyDetailName As String) As String
        Dim connect As New Connection()
        Try
            Dim jss As New JavaScriptSerializer()
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            Dim query As New StringBuilder
            If errMsg.Length = 0 Then
                query.Append("UPDATE  [oHierarchyDetail] SET ")
                query.Append(" [HierarchyDetailName] =  @Param1")
                query.Append(" WHERE [HierarchyDetailID] = @Param2")
                Dim count As Integer = connect.Object_Execute_SAP(query.ToString(), New Object() {hierarchyDetailName, _
                                                                                                  hierarchyDetailID})
            Else
                Return errMsg
            End If
        Catch ex As Exception
            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Public Function DeleteHierarchyDetail(ByVal dataBaseName As String, ByVal hierarchyDetailID As String) As String
        Dim connect As New Connection()
        Try
            Dim errMsg As String = connect.setSQLDB(dataBaseName)
            If errMsg.Length = 0 Then
                Dim params = New Object() {hierarchyDetailID}
                Dim query As New StringBuilder
                Dim dicParams As New Dictionary(Of String, String)
                dicParams.Add("@HierarchyDetailID", hierarchyDetailID)
                Dim count As Integer = connect.Object_Execute_Stored("sp_Delete_HierarchyDetail", dicParams)
            Else
                Return errMsg
            End If
        Catch ex As Exception
            Return ex.Message
        End Try
        Return String.Empty
    End Function
    Class HierarchyDetail
        Property HierarchyDetailID As Integer
        Property HierarchyID As Integer
        Property HierarchyDetailName As String
        Property HierarchyFatherID As Integer
        Property LineStatus As String
        Public Sub New()
        End Sub
    End Class
End Class
